using System;
using UnityEngine;

public class ScController : MonoBehaviour
    {
        private bool _isOnMove;
        private Vector3 _pointerOffset;
        private bool _finishedDrag;
        private Transform _headTransform;
        
        private Camera _camera;

        private void Awake()
        {
            _camera = Camera.main;
            _headTransform = transform.GetChild(0);
        }

        private void Update()
        {
            _headTransform.rotation = Quaternion.Euler(0, 0, _headTransform.eulerAngles.z - 2);
        }

        private void OnMouseDown()
        {
            _pointerOffset = transform.position - _camera.ScreenToWorldPoint(Input.mousePosition);
            _finishedDrag = false;
        }

        private void OnMouseDrag()
        {
            Vector3 newPosition = _camera.ScreenToWorldPoint(Input.mousePosition) + _pointerOffset;
            transform.position = new Vector3(newPosition.x, newPosition.y, transform.position.z);
        }

        private void OnMouseUp()
        {
            _finishedDrag = true;
        }

        public bool GetFinishedDrag()
        {
            return _finishedDrag;
        }
    }

